import { FormItemRule } from "naive-ui";
import { useThingStore } from "@/store/modules/thing";
import { storeToRefs } from "pinia";
const thingStore = useThingStore();
const { types } = storeToRefs(thingStore);
const publicFormConfig: Record<string, any> = {
	isVertical: true,
	labelWidth: 80,
	labelPlacement: "top",
	formItems: [
		{
			field: "tag",
			labelName: "类型",
			labelStyle: "fontSize:14px;fontWeight:bold;",
			type: "RadioBox",
			name: "radioBox",
			options: [
				{
					label: "寻物启事",
					value: "寻物启事",
				},
				{
					label: "认领启事",
					value: "认领启事",
				},
			],
		},
		{
			field: "type_id",
			labelName: "分类",
			labelStyle: "fontSize:14px;fontWeight:bold;",
			type: "Select",
			placeholder: "-请选择一个类别-",
			selectWidth: "180px",
			// options: types.value.map((item) => {
			// 	return {
			// 		label: item.TYPE,
			// 		value: item.id,
			// 	};
			// }),
		},
		{
			field: "title",
			labelName: "标题",
			labelStyle: "fontSize:14px;fontWeight:bold;color:#000;",
			type: "Input",
			inputType: "text",
			placeholder: "",
		},
		{
			field: "content",
			labelName: "详情",
			labelStyle: "fontSize:14px;fontWeight:bold;",
			type: "TextArea",
			inputType: "textarea",
			placeholder: "",

			autosize: {
				minRows: 3,
				maxRows: 5,
			},
		},
		{
			field: "location",
			labelName: "地点",
			placeholder: "",
			labelStyle: "fontSize:14px;fontWeight:bold;",
			type: "Input",
			inputType: "text",
		},
	],
	rules: {
		tag: {
			required: true,
			trigger: ["input"],
			message: "请选择类型",
			validator(rule: FormItemRule, value: string) {
				if (value.length === 0) {
					return new Error("未选择类型");
				}
				return true;
			},
		},
		type_id: {
			required: true,
			trigger: ["input"],
			message: "请选择分类",
			validator(rule: FormItemRule, value: string) {
				if (value.length === 0) {
					return new Error("未选择分类");
				}
				return true;
			},
		},
		title: {
			required: true,
			trigger: ["input"],
			message: "请输入标题",
			validator(rule: FormItemRule, value: string) {
				if (value.trim().length === 0) {
					return new Error("标题为空");
				}
				return true;
			},
		},
		content: {
			required: true,
			trigger: ["input"],
			message: "请输入详情",
			validator(rule: FormItemRule, value: string) {
				if (value.trim().length === 0) {
					return new Error("详情为空");
				}
				return true;
			},
		},
		location: {
			required: true,
			trigger: ["input"],
			message: "请输入地点",
			validator(rule: FormItemRule, value: string) {
				if (value.trim().length === 0) {
					return new Error("地点为空");
				}
				return true;
			},
		},
	},
};
export default publicFormConfig;
